import pyciv.dictionary
import pyciv.hexagon
import pyciv.player
import pyciv.terrain
import pyciv.worker

class State(object):
    def __init__(self, radius=5):
        self.radius = radius
        self.hexes  = pyciv.hexagon.create_list(self.radius)
        self.turn   = 1
        self.players = [pyciv.player.Default()]
        self.current_player = 0
        self.owner = pyciv.dictionary.WithDefault(self.valid_hex, self.players[0])
        self.worker = pyciv.dictionary.WithDefault(self.valid_hex, pyciv.worker.NONE)
        self.terrain = pyciv.dictionary.WithDefault(self.valid_hex, pyciv.terrain.FIELDS)
            
    def valid_hex(self, hex):
        return (pyciv.hexagon.get_distance(pyciv.hexagon.ORIGO,
                                           hex) <= self.radius)

    def has_current_player_as_neighbour(self, hex):
        neighbours = pyciv.hexagon.get_neighbours(hex)
        for neighbour in neighbours:
            if self.valid_hex(neighbour):
                if (self.owner[neighbour] == self.players[self.current_player]):
                    return True
        return False
